package main

import "fmt"

func main() {
	nums := []int{-1, 0, 3, 5, 9, 12}
	target := 9
	fmt.Println(search(nums, target))
}

//#link: https://leetcode-cn.com/problems/binary-search/
func search(nums []int, target int) int {
	left, right := 0, len(nums)
	for left < right {
		mid := left + (right-left)>>1
		if midValue := nums[mid]; midValue < target {
			left = mid + 1
		} else if midValue > target {
			right = mid
		} else {
			return mid
		}
	}
	return -1
}
